<template>
  <div class="common-layout">
    <Navbar />
    <div class="page-container">
      <!-- 侧边栏筛选区 -->
      <aside class="sidebar" v-if="showSidebar">
        <h3>{{ sidebarTitle }}</h3>
        <slot name="sidebar"><!-- 侧边栏内容插槽 --></slot>
      </aside>

      <!-- 主内容区 -->
      <main class="content">
        <div class="content-header">
          <h1>{{ pageTitle }}</h1>
          <div class="content-actions">
            <slot name="actions"><!-- 操作按钮插槽 --></slot>
          </div>
        </div>

        <!-- 加载状态 -->
        <div v-if="loading" class="loading">加载中...</div>

        <!-- 空数据状态 -->
        <div v-else-if="isEmpty" class="empty-state">{{ emptyText }}</div>

        <!-- 主内容插槽 -->
        <div v-else class="content-body">
          <slot name="content"><!-- 主要内容插槽 --></slot>
        </div>
      </main>
    </div>
  </div>
</template>

<script setup lang="ts">
import Navbar from './Navbar.vue';
import { defineProps } from 'vue';

// 定义通用页面属性
const props = defineProps({
  // 页面标题
  pageTitle: { type: String, required: true },
  // 侧边栏标题
  sidebarTitle: { type: String, default: '筛选条件' },
  // 是否显示侧边栏
  showSidebar: { type: Boolean, default: true },
  // 加载状态
  loading: { type: Boolean, default: false },
  // 是否为空数据状态
  isEmpty: { type: Boolean, default: false },
  // 空数据提示文本
  emptyText: { type: String, default: '暂无数据' }
});
</script>

<style scoped>
.common-layout {
  min-height: 100vh;
  background-color: #f8fafc;
}

.page-container {
  display: flex;
  max-width: 1200px;
  margin: 80px auto 0;
  padding: 24px 16px;
  gap: 24px;
}

.sidebar {
  width: 240px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  padding: 24px;
  height: fit-content;
}

.sidebar h3 {
  margin: 0 0 16px 0;
  color: #1e293b;
  font-size: 18px;
  font-weight: 600;
}

.content {
  flex: 1;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  padding: 24px;
}

.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e2e8f0;
}

.content-header h1 {
  margin: 0;
  color: #1e293b;
  font-size: 24px;
  font-weight: 600;
}

.content-actions {
  display: flex;
  gap: 12px;
}

.loading {
  text-align: center;
  padding: 48px;
  color: #64748b;
  font-size: 16px;
}

.empty-state {
  text-align: center;
  padding: 48px;
  color: #64748b;
  font-size: 16px;
}

.content-body {
  min-height: 400px;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .page-container {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
  }
}
</style>